﻿using KalevaAalto.DataPart.Excel.Base;
using OfficeOpenXml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace KalevaAalto.DataPart.Excel.Epplus
{
    internal class EpplusWorksheets : BaseWorksheets
    {
        private ExcelWorksheets _worksheets;
        public EpplusWorksheets(BaseWorkbook workbook,ExcelWorksheets worksheets):base(workbook)
        {
            _worksheets = worksheets;
        }

        public override BaseWorksheet this[int index] => new EpplusWorksheet(this,_worksheets[index]);

        public override BaseWorksheet this[string worksheetName] => new EpplusWorksheet(this, _worksheets[worksheetName]);

        public override BaseWorksheet Add(string worksheetName)
        {
            return new EpplusWorksheet(this, _worksheets.Add(worksheetName));
        }



        public override bool Remove(string worksheetName)
        {
            if(_worksheets.Any(it=>it.Name == worksheetName))
            {
                _worksheets.Delete(worksheetName);
                return true;
            }
            else
            {
                return false;
            }
        }

        public override IEnumerator<BaseWorksheet> GetEnumerator()
        {
            return _worksheets.Select(it => new EpplusWorksheet(this, it)).GetEnumerator();
        }

        






    }
}
